-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial support for listing voices and languages #7
base: main
Are you sure you want to change the base?
Conversation
Fixes some issue on filterOnRecommendec lowQuality output
You can convert this to a draft PR and move it back to a PR once it's ready rather than putting [WIP] as a prefix. |
|
||
return new Promise((resolve, _reject) => { | ||
|
||
let counter = 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the reason that you need to check the voices every 10ms 1000 times? I imagine it's a hack to deal with browsers, but why those values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's 1000 times at the worst condition, which end with the return of an empty array.
In Firefox and Safari Speech API works at start both in a script in the header deferred or not
In Chrome Speech API is available just before the fire of the 'DOMContentLoaded' event in a deferred script
In Edge the more slowness browser Speech API is available in about 60ms in my computer.
So more or less a counter between 10 to 100 is better than 1000 that could be too long.
Do you think to an alternative to catch the result of getVoices()
?
@@ -0,0 +1,26 @@ | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something to think about in a future version is to come up with a way of compressing this data. Adding all these strings to a JS bundle is a significant size increase (est. ~60KB based on minified data.js
). This could be done with, for example, the CompressionStream API and/or a more efficient encoding. Let me know your thoughts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Thorium / navigator in some cases we pass lots of textual data (serialized JSON) via URL query parameters to guarantee that the webview / iframe resolves the data "synchronously" (instant access). We use code that looks like this (there is some usage of NodeJS / Electron Buffer API but nothing that couldn't be pure Web API):
const json = { /* LOTS OF DATA */ };
const jsonStr = JSON.stringify(json);
const cs = new CompressionStream("gzip");
const csWriter = cs.writable.getWriter();
csWriter.write(new TextEncoder().encode(jsonStr));
csWriter.close();
const buff = Buffer.from(await new Response(cs.readable).arrayBuffer());
const b64 = buff.toString("base64");
// pass b64 as escaped URL query parameter
The inverse operation:
const buff = Buffer.from(b64, "base64");
const cs = new DecompressionStream("gzip");
const csWriter = cs.writable.getWriter();
csWriter.write(buff);
csWriter.close();
const buffer = Buffer.from(await new Response(cs.readable).arrayBuffer());
const jsonStr = new TextDecoder().decode(buffer);
const json = JSON.parse(jsonStr);
Based on this latest commit, I've identified a bug with Finnish and Filipino. In Edge, while testing the demo I noticed that the Filipino voices are listed under Finnish > Philippines and that Filipino is not listed in the list of languages. |
I've also inspected the output in Edge and noticed that the Microsoft Natural Voices have an incorrect value for This value seems to be skipped by the code importing the JSON data. |
I don't understand where you set the |
On Android I've noticed that I cannot select some voices available in the demo. All languages supported officially work fine, but if I select "Chinese" for example, the list of voices is never loaded. Here's a list of languages that seem affected:
As you can notice, quite a lot of languages also seem to have missing translations in Instead of "hello world", I think that we should just default to an empty string when there's no test utterance. |
…trict equality when no quality and altNames are available (default comparaison)
Fixes #6
Fixes #5
Fixes #4
|
remanage : sortBy function to handle localization by default remove the promise return of getLanguages, only getVoices can fetch SpeechSynthesisVoices and parse it.
export const defaultRegion = ${JSON.stringify(defaultRegion)}; | ||
`; | ||
|
||
const filePath = './src/data.ts'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This source file is script-generated, may I suggest:
- adding a comment header at the top of the file that explains which script produced the Typescript code, and at what date/time (or ideally: git revision / commit hash).
- locate the generated file inside a "gen" subfolder or the "src" source tree, or to rename the file e.g.
src/data.gen.ts
if (Array.isArray(voices) && voices.length) return resolve(voices); | ||
setTimeout(tick, 10); | ||
} | ||
setTimeout(tick, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setTimeout()
has a resolution of about 20ms, last time I checked. Also, IIRC this is affected by browser window visibility (it doesn't really matter for this use-case though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... I think that a 200ms tick would be fine for this.
function filterOnGender(voices: IVoices[], gender: TGender): IVoices[] | ||
|
||
function filterOnGender(voices: IVoices[], gender: TGender): IVoices[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove duplicate
function filterOnGender(voices: IVoices[], gender: TGender): IVoices[] |
No description provided.